package com.app.controller;

import com.app.model.EminentPersonModel;
import com.app.service.EminentPersonService;
import com.app.util.CommonHelp;
import com.app.util.Result;
import com.app.vo.EminentPersonVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

//创业达人
@RestController
@Controller
@RequestMapping("/jiuquan/eminentPerson")
public class EminentPersonController {
    @Autowired
    private EminentPersonService eminentPersonService;

    //查询列表
    @GetMapping("/getEminentPersonList")
    public Result getEminentPersonList(@RequestParam(defaultValue = "0") Integer page,
                                       @RequestParam(defaultValue = "10") Integer limit, String keyword) {
        EminentPersonVo eminentPersonList = eminentPersonService.getEminentPersonList(page, limit, keyword);
        return Result.success(eminentPersonList);
    }

    //详情
    @GetMapping("/getEminentPersonById")
    public Result getEminentPersonById(Integer id) {
        EminentPersonModel eminentPerson = eminentPersonService.getById(id);
        return Result.success(eminentPerson);
    }

    //新增和修改
    @PostMapping("/addAndUpdateEminentPerson")
    public Result addAndUpdateEminentPerson(@RequestBody EminentPersonModel eminentPersonModel) {
        EminentPersonModel eminentPerson = eminentPersonService.getById(eminentPersonModel.getId());
        if (eminentPerson != null) {
            eminentPersonModel.setUpdateTime(CommonHelp.getNowTimestamp());
            eminentPersonService.updateById(eminentPersonModel);
            return Result.success("修改成功");
        } else {
            eminentPersonModel.setCreateTime(CommonHelp.getNowTimestamp());
            eminentPersonService.save(eminentPersonModel);
            return Result.success("添加成功");
        }
    }

    //删除
    @GetMapping("/delEminentPerson")
    public Result delEminentPerson(Integer id) {
        eminentPersonService.removeById(id);
        return Result.success("删除成功");
    }
}
